<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>DES Decryption</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>
</head>
<body>
    <h2>DES 密文解密</h2>
    <label for="encrypted">密文:</label>
    <input type="text" id="encrypted" value="PzuwKm29UOigz84T8EXfeA=="><br><br>
    <label for="key">密钥:</label>
    <input type="text" id="key" value="19142405862"><br><br>
    <button onclick="decrypt()">解密</button>
    <h3>解密结果:</h3>
    <p id="result"></p>

    <script>
        function decrypt() {
            var encryptedText = document.getElementById("encrypted").value;
            var key = document.getElementById("key").value;

            try {
                // 使用 CryptoJS 进行解密
                var keyHex = CryptoJS.enc.Utf8.parse(key.substring(0, 8)); // DES 密钥需要 8 字节
                var decrypted = CryptoJS.DES.decrypt({
                    ciphertext: CryptoJS.enc.Base64.parse(encryptedText)
                }, keyHex, {
                    mode: CryptoJS.mode.ECB,
                    padding: CryptoJS.pad.Pkcs7
                });

                var result = decrypted.toString(CryptoJS.enc.Utf8);
                document.getElementById("result").innerText = result || "解密失败";
            } catch (e) {
                document.getElementById("result").innerText = "解密错误: " + e.message;
            }
        }
    </script>
</body>
</html>